﻿using Microsoft.CodeAnalysis.CSharp.Scripting;
using Microsoft.CodeAnalysis.Scripting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NoORM.Core.ServiceScript
{
    public class ServiceExpression
    {
        public async Task<object> GetExpressionValue(string expression)
        {
            ScriptOptions options = ScriptOptions.Default
                //.AddReferences(typeof(System.Object).Assembly)
                .AddReferences(typeof(System.Linq.Enumerable).Assembly)
                .AddImports("System", "System.Linq", "System.Collections.Generic");
            string code = $"object result = {expression};";
            var result = await CSharpScript.RunAsync(code, options);
            object o = result.GetVariable("result").Value;
            return o;
        }

    }
}
